//index.js
//获取应用实例
const app = getApp();
let api = require('../../utils/api.js');
let util = require('../../utils/util.js');

Page({
  data: {
    indexData: wx.getStorageSync('indexData'),
    recomData: wx.getStorageSync('recomData'),
  },
  curCate(e){
    app.globalData.curCate=e.currentTarget.dataset.index;
  },
  onLoad: function() {
    if (!this.data.indexData) {
      //请求首页数据
      util.merReq(api.indexUrl, {}, (res) => {
        // 保存在data
        let recomDataArr = [];
        recomDataArr = res.data.data.hotGoodsList.concat(res.data.data.newGoodsList);
        this.setData({
          indexData: res.data.data,
          recomData: recomDataArr,
        })
        // 缓存数据
        wx.setStorage({
          key: 'indexData',
          data: res.data.data,
        })
        wx.setStorage({
          key: 'recomData',
          data: recomDataArr,
        })
        console.log(this.data.indexData)
      }, 'GET')
    }
  }
})